package sr.myserver.controller;

import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sr.myserver.entity.SysRoles;
import sr.myserver.service.SysRolesService;
import sr.myserver.vo.SelectData;
import sr.myserver.vo.SysRolesEdit;
import sr.myserver.vo.common.Basic;
import sr.myserver.vo.common.PageRequest;
import sr.myserver.vo.common.PageResponse;

@Slf4j
@RestController
@RequestMapping("/sysroles")
@Api(tags = "权限信息")
public class SysRolesController {

    @Autowired
    SysRolesService sysRolesService;

    @GetMapping("/{id}")
    @Operation(summary = "指定ID获取数据")
    public SysRoles get(@PathVariable("id") String id) {
        return sysRolesService.getEdit(id);
    }

    @PostMapping
    @Operation(summary = "添加数据")
    public Basic.Response post(@RequestBody SysRolesEdit entity) {
        entity.setId(null);
        return sysRolesService.add(entity);
    }

    @PutMapping("/edit")
    @Operation(summary = "指定ID修改数据")
    public Basic.Response put(@RequestBody SysRolesEdit entity) {
        return sysRolesService.update(entity);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "指定ID删除数据")
    public Basic.Response delete(@PathVariable("id") String id) {
        return sysRolesService.deleteById(id);
    }

    @PutMapping
    @Operation(summary = "分页列表数据")
    public PageResponse<SysRoles> queryTables(@RequestBody PageRequest request) {
        return sysRolesService.queryTables(request);
    }

    @PostMapping("/select")
    @Operation(summary = "分页下拉数据")
    public PageResponse<SelectData> querySelect(@RequestBody PageRequest request) {
        return sysRolesService.querySelect(request);
    }
}

